var mysql = require('mysql');
var express = require('express');
var app = express();
var connection = mysql.createConnection({
  host: '127.0.0.1',
  port: '3306',
  user: 'root',
  password: 'admin',
  database: 'db_login'
})
connection.connect();
var getSql = 'SELECT * FROM message';
var str = '';
connection.query(getSql, function(err, result){
  if(err)
    console.log('SELECT ERROR:' + err);
  console.log(result);
  str = JSON.stringify(result);
  console.log(str);
});
app.get('/', function(req, res) {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.send(str);
});

app.listen(3000, function(){
  console.log("Server running at 3000 port");
})